from django.conf.urls.static import static
from django.contrib import admin
from django.urls import path, include
from django.views.static import serve

from . import settings

from apps.user.views import RegisterView, LoginView, LogoutView, UserInfoView, UserOrderView, AddressView
from apps.goods.views import IndexView, GoodDetailView, GoodsListView, YouhuiquanView
from apps.cart.views import CartView, CartAddView, CartUpdateView, CartDelView
from apps.order.views import OrderPlaceView, OrderCommitView, OrderCommentView, OrderDirView

urlpatterns = [
                path('admin/', admin.site.urls),

                path('user/login/', LoginView.as_view(), name='login'),  # 登录页
                path('user/register/', RegisterView.as_view(), name='register'),  # 注册页
                path('user/logout/', LogoutView.as_view(), name='logout'),
                path('user/order/<int:page>/', UserOrderView.as_view(), name='order'),
                path('user/address/', AddressView.as_view(), name='site'),
                path('user/', UserInfoView.as_view(), name='info'),

                path('search/', include('haystack.urls')),

                path('cart/add/', CartAddView.as_view(), name='cart_add'),
                path('cart/update/', CartUpdateView.as_view(), name='cart_update'),
                path('cart/del/', CartDelView.as_view(), name='cart_del'),
                path('cart/', CartView.as_view(), name='cart'),


                path('order/place/', OrderPlaceView.as_view(), name='order_place'),
                path('order/commit/', OrderCommitView.as_view(), name='order_commit'),
                path('order/comment/<int:order_id>/', OrderCommentView.as_view(), name='order_comment'),
                path('order/place/dir/', OrderDirView.as_view(), name='directly_place'),
                path('', IndexView.as_view(), name='home'),

                path('media/<path:path>/', serve, {'document_root': settings.MEDIA_ROOT}),
                path('goods/detail/<int:good_id>/', GoodDetailView.as_view(), name="detail"),
                path('goods/list/<int:type_id>/<int:page>/', GoodsListView.as_view(), name="list"),
                path('goods/select/', YouhuiquanView.as_view())
              ] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
